#region File Description
//-----------------------------------------------------------------------------
// OptionsMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using AIniciacao.Lib;
using System;
using AIniciacao.Lib.GameUtils;
using AIniciacao.Lib.Resources;
using AIniciacao.Screens;
#endregion

namespace AIniciacao.MenuScreens
{
    /// <summary>
    /// The options screen is brought up over the top of the main menu
    /// screen, and gives the user a chance to configure the game
    /// in various hopefully useful ways.
    /// </summary>
    class OptionsMenuScreen : MenuScreen
    {
        #region Fields

		ContentManager content;
		Texture2D background;

		MenuEntry mainVolumeMenuEntry;
        MenuEntry languageMenuEntry;
        MenuEntry backMenuEntry;
		
        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public OptionsMenuScreen()
            : base(AIniciacaoResourceManager.getProperty("label_options"))
        {
			// Create our menu entries.
            mainVolumeMenuEntry = new MenuEntry(string.Empty);
            languageMenuEntry = new MenuEntry(string.Empty);

           
            SetMenuEntryText();
            SetMenuLanguageText();
            backMenuEntry = new MenuEntry(AIniciacaoResourceManager.getProperty("label_back"));

            // Hook up menu event handlers.
            mainVolumeMenuEntry.Selected += MainVolumeEntrySelected;

            languageMenuEntry.Selected += LanguageEntrySelected;
            backMenuEntry.Selected += OnCancel;
            
            // Add entries to the menu.
            MenuEntries.Add(mainVolumeMenuEntry);
            MenuEntries.Add(languageMenuEntry);
            MenuEntries.Add(backMenuEntry);
        }


        /// <summary>
        /// Fills in the latest values for the options screen menu text.
        /// </summary>
        void SetMenuEntryText()
        {
            mainVolumeMenuEntry.Text = String.Format("Volume: {0} %", Settings.MainVolume);
            
			
        }
        void SetMenuLanguageText()
        {
            languageMenuEntry.Text = AIniciacaoResourceManager.getProperty("label_language") +":"+Settings.CultureInfo.Name;
        }

        #endregion

		#region Load Content

		public override void LoadContent()
		{
			if (content == null) 
                    content = new ContentManager(ScreenManager.Game.Services, "Content");
			background = content.Load<Texture2D>(GamePathObjects.AIniciacaoMenuBackgroundOptionsPath);
			CenterTitle();
		}

		#endregion


        #region Handle Input

		/// <summary>
		/// Event handler for when the Main Volume menu entry is selected.
		/// </summary>
		void MainVolumeEntrySelected(object sender, PlayerIndexEventArgs e)
		{
			Settings.MainVolume += 5;
			if (Settings.MainVolume > 100) Settings.MainVolume = 0;

			SetMenuEntryText();
		}
        void LanguageEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            if (Settings.CultureInfo.Name.Equals("pt-BR"))
                Settings.CultureInfo = new System.Globalization.CultureInfo("en-US");
            else
                Settings.CultureInfo = new System.Globalization.CultureInfo("pt-BR");
            SetMenuLanguageText();
        }


        #endregion

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
            backMenuEntry.Text = AIniciacaoResourceManager.getProperty("label_back");
            menuTitle = AIniciacaoResourceManager.getProperty("label_options");
        }
		#region Drawing
        
		public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
            byte fade = TransitionAlpha;

            Color transitionColor = new Color(fade, fade, fade);

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

                spriteBatch.Draw(background, fullscreen, transitionColor);                

            spriteBatch.End();

            base.Draw(gameTime);
        }

        #endregion
    }
}
